//
//  ExaminationRoomViewController.m
//  CoachsBook
//
//  Created by huiyong li on 2022/8/24.
//

#import "ExaminationRoomViewController.h"
#import "ExaminationRoomModel.h"
#import "ExaminationRoomCell.h"
#import "LongSearchBar.h"

@interface ExaminationRoomViewController ()<UISearchBarDelegate>

@end

@implementation ExaminationRoomViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navgationheadv.titlelabel.text = @"考试安排";
    self.offset = 1;
}

- (void)setupUI {
    [super setupUI];
    
    LongSearchBar *searchBox = [[LongSearchBar alloc]initWithType:LongSearchBarExaminationRoom WithFrame:CGRectMake(16, SafeAreaTopHight+10, APPwidth-32, 40)];
    searchBox.delegate = self;
    [self.view addSubview:searchBox];
    
    self.refreshState = JKRefreshStateLoading;
    self.tableView.frame = CGRectMake(0, SafeAreaTopHight+60, APPwidth, APPheight-SafeAreaTopHight-60);
    
}


- (void)getData
{
    for (NSInteger i=0; i<(self.offset)*WKLLimit; i++) {
        
        ExaminationRoomModel *model = [[ExaminationRoomModel alloc]init];
        model.ExaminationRoomID = [NSString stringWithFormat:@"%ld",i];
        model.ExaminationRoomName = [NSString stringWithFormat:@"长沙支队安沙科目%ld分考场",i];
        model.ExaminationRoomAddress = [NSString stringWithFormat:@"湖南省长沙县安沙镇毛塘工业园%ld",i];
        model.ExaminationRoomCarType = [NSString stringWithFormat:@"C1、C2、D、E、F、C5"];
        if (i==1) {
            model.ExaminationRoomName = [NSString stringWithFormat:@"长沙支队安沙科目三分考场长沙支队安沙科目三分考场长沙支队安沙科目三分考场长沙支队安沙科目三分考场"];
            model.ExaminationRoomAddress = [NSString stringWithFormat:@"湖南省长沙县安沙镇毛塘工业园湖南省长沙县安沙镇毛塘工业园湖南省长沙县安沙镇毛塘工业园湖南省长沙县安沙镇毛塘工业园湖南省长沙县安沙镇毛塘工业园湖南省长沙县安沙镇毛塘工业园"];
        }
        [self.dataArray addObject:model];
    }
    self.refreshState = JKRefreshStateFinish;
    [self.tableView reloadData];
}


#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    ExaminationRoomModel *model = self.dataArray[indexPath.row];
    
    CGFloat nameLabelh = [LongHelper textHeight:model.ExaminationRoomName WithUIFont:kPingFangRegular(14) AndWidth:APPwidth-70-70];
    if (nameLabelh < 20) {
        nameLabelh = 20;
    }
    CGFloat addressLabelh = [LongHelper textHeight:model.ExaminationRoomAddress WithUIFont:kPingFangRegular(14) AndWidth:APPwidth-70-70];
    if (addressLabelh < 20) {
        addressLabelh = 20;
    }
    CGFloat cartypeLabelh = [LongHelper textHeight:model.ExaminationRoomCarType WithUIFont:kPingFangRegular(14) AndWidth:APPwidth-70-70];
    if (cartypeLabelh < 20) {
        cartypeLabelh = 20;
    }
    return nameLabelh+addressLabelh+cartypeLabelh+55;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    ExaminationRoomCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ExaminationRoomCell"];
    if (!cell) {
        cell=[[ExaminationRoomCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"ExaminationRoomCell"];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    [cell cellFillWithModel:self.dataArray[indexPath.row]];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 20;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    UIView *view = [[UIView alloc]init];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

#pragma mark ---UISearchBarDelegate搜索框
- (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar
{
    if ([LongHelper isBlankString:searchBar.text]) {
        [SVProgressHUD showErrorWithStatus:@"请输入搜索内容"];
        return;
    }
    NSLog(@"搜索筛选");
    
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [self.view endEditing:YES];
    NSLog(@"按钮搜索筛选");
}


@end
